package com.zjitc.service.impl;
import com.zjitc.dao.UserDao;
import com.zjitc.model.User;
import com.zjitc.service.UserService;
import com.zjitc.util.RedisUtils;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/16 16:37
 * @description:
 */
@Service
public class UserServiceImpl implements UserService{

  @Autowired
  private UserDao userDao;


  @Override
  public User doLogin(String username, String password) {
    int count = userDao.checkUsername(username);
    if (count != 1) {
      return null;
    }
    User user = userDao.findByUserNameAndPassword(username, password);
    if (user == null) {
      return null;
    }

    return user;
  }


  @Override
  public User doRegist(User user) {
    int count=userDao.checkUsername(user.getUsername());
    if (count == 1){
      return null;
    }else {
      userDao.register(user);
      return null;
    }


  }

  @Override
  public String findEmailByUsername(String username) {
    String Email=userDao.findEmailByUsername(username);
    return Email;
  }

  @Override
  public int findUsername(String username) {
    int count=userDao.checkUsername(username);
    if (count==1){
      return 1;
    }
    return 0;
  }

  @Override
  public void updatePassword(String username, String password) {
    userDao.updatePassword(username,password);
  }



}
